package com.nbsaas.boot.app.rest.convert;

import com.nbsaas.boot.app.api.domain.response.AppRoleResponse;
import com.nbsaas.boot.app.data.entity.AppRole;
import com.nbsaas.boot.rest.api.Converter;
import com.nbsaas.boot.utils.BeanDataUtils;

/**
 * 角色-实体对象转化成响应对象
 */

public class AppRoleResponseConvert implements Converter<AppRoleResponse, AppRole> {

    @Override
    public AppRoleResponse convert(AppRole source) {
        AppRoleResponse result = new AppRoleResponse();
        BeanDataUtils.copyProperties(source, result);
        if (source.getApp() != null) {
            result.setApp(source.getApp().getId());
        }

        try {
            if (source.getApp() != null) {
                result.setAppName(source.getApp().getName());
            }
        } catch (Exception ignored) {
        }

        if (source.getRoleType() != null) {
            result.setRoleTypeName(String.valueOf(source.getRoleType()));
        }
        return result;
    }

}

